
package net.atremmedia.gwt.actionjava.examples.bounds.samples;

import net.atremmedia.gwt.actionjava.examples.AJExample;
import net.atremmedia.gwt.actionjava.examples.bounds.samples.faces.Face;
import net.atremmedia.gwt.actionjava.examples.bounds.samples.faces.Face1;
import net.atremmedia.gwt.actionjava.examples.bounds.samples.faces.Face2;
import net.atremmedia.gwt.actionjava.examples.bounds.samples.faces.Face3;
import net.atremmedia.gwt.actionjava.examples.bounds.samples.faces.Face4;
import net.atremmedia.gwt.actionjava.examples.frame.AJExampleOverview;
import actionjava.display.TextField;
import com.allen_sauer.gwt.log.client.Log;

public class DrawGraphicsBounds extends AJExample
{
	/*
	 * Download FLA source files:
	 * http://www.actionjava.com/fla.zip
	 */

	public static final String NAME = "Draw Graphics bounds";
	public static final String DESCRIPTION = "Description";
	public static final String EXAMPLE_SRC = "https://code.google.com/p/gwt-actionjava/source/browse/trunk/aj-examples/aj-examples-bounds/src/main/java/net/atremmedia/gwt/actionjava/examples/bounds/samples/DrawGraphicsBounds.java";

	private Face face;

	public DrawGraphicsBounds(AJExampleOverview base)
	{
		super(NAME, DESCRIPTION, EXAMPLE_SRC, base);
	}

	@Override
	public void run()
	{
		int key = (int) getRandomNumber(1, 4);

		switch (key) {
			case 1:
				face = new Face1();
				break;

			case 2:
				face = new Face2();
				break;

			case 3:
				face = new Face3();
				break;

			case 4:
				face = new Face4();
				break;
		}

		face.setX((getWidth() / 2));
		face.setY((getHeight() / 2));

		addChild(face);

		displayBounds(Math.round(face.getWidth()), Math.round(face.getHeight()));
	}

	public void displayBounds(double width, double height)
	{
		drawText(10, 10, 15, "Width: ");
		drawText(65, 12, String.valueOf(width));

		drawText(10, 30, 15, "Height: ");
		drawText(65, 32, String.valueOf(height));

		Log.debug("width " + width + " height: " + height);
	}

	public void drawText(double x, double y, String text)
	{
		TextField textF = new TextField(text);
		textF.setX(x);
		textF.setY(y);
		textF.setSize(12);

		addChild(textF);
	}

	public void drawText(double x, double y, int fontSize, String text)
	{
		TextField textF = new TextField(text);
		textF.setX(x);
		textF.setY(y);
		textF.setSize(fontSize);

		addChild(textF);
	}
}
